package com.example.shushiyunsst.fragment.main.home.child.miner22.mother_icon

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.library_common.adapter.JssBaseQuickAdapter
import com.example.library_common.adapter.JssBaseViewHolder
import com.example.library_common.base.BaseFragmentEx
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.bean.MotherIconBean
import com.example.shushiyunsst.fragment.main.home.child.bean.MotherIconSubListBean
import com.example.wallet.db.UserInfoManager
import kotlin.math.log

class MotherIconRecorderListFragment : BaseFragmentEx() {

    companion object {
        fun newInstance(): MotherIconRecorderListFragment {
            val args = Bundle()
            val fragment = MotherIconRecorderListFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private val userInfo = UserInfoManager.userInfoManager.getUserInfoWrapper()?.userInfo

    private var mBean: MotherIconBean? = null

    fun setBean(mBean: MotherIconBean?) {
        this.mBean = mBean
        mAdapter?.data?.clear()
        mBean?.scmlBalanceLog?.let {
            mAdapter?.data?.addAll(it)
            mAdapter?.notifyDataSetChanged()
        }
    }

    private var mRecyclerView: RecyclerView? = null

    private var mAdapter: JssBaseQuickAdapter<MotherIconSubListBean>? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport = false
    }

    override fun getLayoutId(): Any {
        return R.layout.mother_icon_recorder_list_fragment
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mRecyclerView = view.findViewById(R.id.mRecyclerView)
        mRecyclerView?.setHasFixedSize(true)
        mRecyclerView?.layoutManager =
            LinearLayoutManager(_mActivity, LinearLayoutManager.VERTICAL, false)

        mAdapter = object :
            JssBaseQuickAdapter<MotherIconSubListBean>(R.layout.mother_icon_recorder_item_list_fragment) {
            override fun convert(holder: JssBaseViewHolder?, item: MotherIconSubListBean?) {
                holder
                    ?.setViewVisible(R.id.brandAra, holder.layoutPosition ==0)
                    ?.setViewVisible(R.id.brand, holder.layoutPosition ==0)
                    ?.setViewVisible(
                        R.id.mother_icon_synthesis,
                        item?.logType == MotherIconSubListBean.MOTHER_ICON_SYNTHESIS
                    )
                    ?.setViewVisible(
                        R.id.mother_icon_transfer,
                        item?.logType == MotherIconSubListBean.MOTHER_ICON_TRANSFER
                    )
                    ?.setViewVisible(
                        R.id.mother_icon_income,
                        item?.logType == MotherIconSubListBean.MOTHER_ICON_INCOME
                    )
                    ?.setText(R.id.title, item?.logTypeDesc)
                    ?.setText(R.id.value, "${item?.txNums}")
                    ?.setText(R.id.mother_icon_synthesis_zhi_you, "${item?.scmlZyNums}")
                    ?.setText(R.id.mother_icon_synthesis_left, "${item?.cmlZyNums}")
//                    ?.setText(R.id.mother_icon_synthesis_address, "链 ${item?.walletAddress}")
                    ?.setText(R.id.mother_icon_income_address_payer, "${item?.walletAddress}")
//                    ?.setText(R.id.mother_icon_income_address_payee, " ${userInfo?.sysWalletAddress}")
                    ?.setText(R.id.mother_icon_transfer_address_payee, "${item?.walletAddress}")
//                    ?.setText(R.id.mother_icon_transfer_address_payer, "付款方 ${userInfo?.sysWalletAddress}")
                    ?.setText(R.id.mother_icon_transfer_type,"${item?.optTypeDesc}")
                    ?.setText(R.id.mother_icon_transfer_tokenType,"${item?.tokenType}")
                    ?.setText(R.id.mother_icon_income_type,"${item?.optTypeDesc}")
                    ?.setText(R.id.mother_icon_income_tokenType,"${item?.tokenType}")
                    ?.setText(R.id.timeTv,"${item?.createTime}")
                    ?.setTextColorRes(
                        R.id.value, when (item?.logType) {
                            MotherIconSubListBean.MOTHER_ICON_TRANSFER->R.color.text_color_16
                            else -> R.color.PrimaryColor
                        }
                    )
//                Log.d("convert", "item?.walletAddress == userInfo?.sysWalletAddress: ${item?.walletAddress == userInfo?.sysWalletAddress}")
            }
        }

        mRecyclerView?.adapter = mAdapter
        setBean(mBean)
    }
}